Skip to content

Injection points SMGR v17#914

Open
a-masterov wants to merge 2 commits intoREL_17_STABLE_neonfrom
amasterov/injpoint-pgxn-17
Open

Injection points SMGR v17#914
a-masterov wants to merge 2 commits intoREL_17_STABLE_neonfrom
amasterov/injpoint-pgxn-17

Conversation

@a-masterov
Copy link

@a-masterov a-masterov commented Mar 10, 2026

We need to test SMGR failures.

This PR adds probability-based injection in the injection_points extension – New error-prob- action so injection points can raise an ERROR with a configurable probability (e.g. for fault-injection tests).

@a-masterov a-masterov marked this pull request as ready for review March 11, 2026 12:21
@a-masterov a-masterov requested a review from HaoyuHuang March 11, 2026 12:21
*/

#include "postgres.h"
#include <time.h>

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's this used for?

Comment on lines +302 to +306
else if (strncmp(action, "error-prob-", 11) == 0)
{
condition.prob = action2prob(action, 11);
function = "injection_error_prob";
}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why error-prob-n-nnnnn and not a suffix that's accepted by strtod? It would simplify action2prob significantly, as it wouldn't need the local copy.

Additionally, couldn't we just pass a pointer to the expected numeric suffix of the action (action + 11, or &action[11])?

return;

/* Use the probability stored in the condition. */
if ((double) rand() / (double) RAND_MAX > condition->prob)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not store condition->prob as fraction of RAND_MAX?

That way, we wouldn't have to do expensive double division and compare operations every time this injection point is hit.

So, condition->prob would equal probability * RAND_MAX, which cancels out with the / (double) RAND_MAX used here, and allows us to directly compare rand() > condition->prob

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants